package server

import (
	"fmt"
	"net/http"
)

func Route() {
	// http这是一个路由框架， 还差一个mvc框架
	http.HandleFunc("/hello",helloHandler)
		// 该目录下的文件
	http.HandleFunc("/file",func(rw http.ResponseWriter, r *http.Request) {
		fmt.Println(r.URL.Path)
		http.ServeFile(rw,r,"http_test.go")
	})
	http.ListenAndServe(":8888",nil)
}
/**
对包中的标识，是所有可见的
*/
func helloHandler(res http.ResponseWriter, rq *http.Request){
	// Request使用来读的
	fmt.Println(rq.Body)
	res.Write([]byte("I have receive the request,你访问的是黎勇的云服务器，欢迎常来光顾"))
}
/**
&{GET /hello HTTP/2.0 
https时变成了http2.0

&{GET /hello HTTP/1.1
*/
func handler(res http.ResponseWriter, rq *http.Request) {
	fmt.Println(rq)
	// 判断请求方法类型
	fmt.Println(rq.Method)
	writeLen,_:=res.Write([]byte("I have receive the request,你访问的是黎勇的云服务器，欢迎常来光顾"))
	fmt.Println("write len:",writeLen)
}